<?php
class Default_Model_Author extends Zend_Db_Table{
    protected $_name="bk_author";
    protected $_id="au_id";
    public function listAuthor($control=true,$index=null)
    {
        if($control)
        {
            return $this->fetchAll()->toArray();
        }
        else
        {
            $query=$this->select();
            $query->where("au_id = ?",$index);
            return $this->fetchRow($query);
        }
        
        
    }
    public function delete_author($au_id=null)
    {
        if($au_id == null)
        return null;
        $select_book=$this->select();
        
        $select_book->from("bk_book","bk_id")
                    ->setIntegrityCheck(false)
                    ->where("bk_author = ? ",$au_id);
        $books=$this->fetchAll($select_book)->toArray();
       
        if(!empty($books))
        {
            $mbook=new Default_Model_Book;
           // Zend_Debug::dump($mbook);
           
            foreach($books as $book)
            $mbook->delete("bk_id=".$book["bk_id"]);
            $this->delete("au_id=".$au_id);
            return true;
        }
        return true;
        //Zend_Debug::dump($books);
        //die();
                    
    }
    
    
    
}